const { DataTypes } = require('sequelize');
const sequelize = require('../config/database');

const ImportExportRecord = sequelize.define('ImportExportRecord', {
  id: {
    type: DataTypes.INTEGER,
    primaryKey: true,
    autoIncrement: true
  },
  type: {
    type: DataTypes.STRING(10),
    allowNull: false,
    comment: '操作类型：导入/导出'
  },
  file_name: {
    type: DataTypes.STRING(255),
    allowNull: false,
    comment: '文件名'
  },
  file_size: {
    type: DataTypes.INTEGER,
    comment: '文件大小(bytes)'
  },
  status: {
    type: DataTypes.STRING(20),
    allowNull: false,
    comment: '状态：进行中/成功/失败/已完成/打包中'
  },
  total_count: {
    type: DataTypes.INTEGER,
    comment: '总数量'
  },
  success_count: {
    type: DataTypes.INTEGER,
    comment: '成功数量'
  },
  fail_count: {
    type: DataTypes.INTEGER,
    comment: '失败数量'
  },
  error_message: {
    type: DataTypes.TEXT,
    comment: '错误信息'
  },
  download_url: {
    type: DataTypes.STRING(255),
    comment: '下载链接'
  },
  duration: {
    type: DataTypes.INTEGER,
    comment: '处理时长(秒)'
  }
}, {
  tableName: 'import_export_records',
  timestamps: true,
  createdAt: 'created_at',
  updatedAt: 'updated_at',
  indexes: [
    {
      name: 'idx_created_at',
      fields: ['created_at']
    }
  ]
});

module.exports = ImportExportRecord; 